package com.keith.jpa.tenant.thread;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.*;

/**
 * ShowThreadPool.java
 * 线程扩展
 *
 * @author czykeih
 * @version 1.0 2023/10/25
 */
@Slf4j
public class ShowThreadPool extends ThreadPoolExecutor {
    public ShowThreadPool(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory, RejectedExecutionHandler handler) {
        super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler);
    }
    @Override
    protected void beforeExecute(Thread t, Runnable r) {
        showLog();
        super.beforeExecute(t, r);
    }

    @Override
    protected void afterExecute(Runnable r, Throwable t) {
        showLog();
        super.afterExecute(r, t);
    }
    private void showLog(){
        log.info("当前线程，核心[{}],最大[{}],活跃:[{}],完成任务数:[{}],任务数:[{}]",getCorePoolSize(),getMaximumPoolSize(),getActiveCount(),getCompletedTaskCount(),getTaskCount());
    }
}
